<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>实例管理</title>
    <link rel="stylesheet" th:href="@{/css/base.css}" media="all">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <script type="text/javascript" th:src="@{/layui/layui.js}"></script>
    <script type="text/javascript" th:src="@{/js/jquery-3.2.0.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/base.js}"></script>
    <style>
        body{
            overflow-y: auto;
        }
    </style>
</head>
<body>
<div class="container container-index">
    <form class="layui-form layui-form-pane" id="search-form" lay-filter="search-form" action="">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">所属分区</label>
                <div class="layui-input-inline">
                    <select name="zoneId">
                        <option value="" selected>请选择</option>
                        <option th:each="item : ${zone}" th:value="${item.id}" th:text="${item.name}"></option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">实例名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" autocomplete="off" class="layui-input" placeholder="请输入">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">主机</label>
                <div class="layui-input-inline">
                    <input type="text" name="host" autocomplete="off" class="layui-input" placeholder="请输入">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">端口</label>
                <div class="layui-input-inline">
                    <input type="text" name="port" autocomplete="off" class="layui-input" placeholder="请输入">
                </div>
            </div>
            <div class="layui-inline">
                <button type="submit" class="layui-btn layui-btn-sm layui-bg-blue" lay-submit
                        lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索
                </button>
                <button type="submit" class="layui-btn layui-btn-sm layui-btn-primary" lay-submit
                        lay-filter="data-reset-btn"><i class="layui-icon">&#xe669;</i> 重 置
                </button>
            </div>
        </div>
    </form>

    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="add"><i class="layui-icon">&#xe654;</i>
                新增
            </button>
        </div>
    </script>

    <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    <script type="text/html" id="currentTableBar">
        <span class="toolbar_span">
                <a src="javascript:void(0)" lay-event="del">删除</a>
                <a src="javascript:void(0)" lay-event="update">编辑</a>
                <a src="javascript:void(0)" lay-event="backup">备份</a>
            </span>
    </script>
</div>


<script type="text/javascript" th:inline="javascript">
    layui.use(['jquery', 'form', 'table', 'layer'], function () {
        const form = layui.form,
            table = layui.table,
            layer = layui.layer;

        var currTable = Asurplus.tableRender({
            table: table,
            form: form,
            url: ctxPath + 'node-info/list',
            cols: [
                [
                    {field: '', title: '', type:'numbers', templet: function (d) {return d.LAY_TABLE_INDEX + 1;}},
                    {field: 'zoneName', title: '所属分区'},
                    {field: 'name', title: '实例名称'},
                    {field: 'className', title: '驱动'},
                    {field: 'host', title: '主机'},
                    {field: 'port', title: '端口'},
                    {field: 'username', title: '用户名'},
                    {field: 'password', title: '密码'},
                    {field: 'remark', title: '备注'},
                    {field: 'createTime', minWidth: 180, title: '创建时间'},
                    {title: '操作', minWidth: 150, toolbar: '#currentTableBar', fixed: 'right'}
                ]
            ]
        });

        // 表头工具
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {
                Asurplus.openLayer({
                    title: '新增',
                    content: ctxPath + 'node-info/node-info-add'
                }, () => {
                    currTable.reload();
                })
                return false;
            }
        });

        // 表行工具
        table.on('tool(currentTableFilter)', function (obj) {
            const data = obj.data;
            // 修改
            if (obj.event === 'update') {
                Asurplus.openLayer({
                    title: '修改',
                    content: ctxPath + 'node-info/node-info-update/' + data.id
                }, () => {
                    currTable.reload();
                })
                return false;
            }
            // 删除
            else if (obj.event === 'del') {
                layer.confirm('确认删除', {
                    btn: ['确定'],
                    title: '提示'
                }, function(index){
                    Asurplus.get({
                        url: ctxPath + 'node-info/delete/' + data.id
                    }, () => {
                        layer.close(index);
                        currTable.reload();
                    });
                });
                return false;
            }
            // 备份
            else if(obj.event === 'backup') {
                Asurplus.openLayer({
                    title: '新建备份',
                    area: ['100%', '100%'],
                    content: ctxPath + 'node-info/node-info-backup/' + data.id
                }, () => {
                    currTable.reload();
                })
                return false;
            }
        });
    })
</script>
</body>
</html>